package no.uio.ifi.cop.util;

/**
 * Missing feature in Java, multiple return values.
 *
 * @version 1.0
 * @author  bjarneh@ifi.uio.no
 */

public class Tuple <A, B>{

    private A one;
    private B two;

    public Tuple(A a, B b){
        one = a;
        two = b;
    }

    public A first(){
        return one;
    }
    
    public B second(){
        return two;
    }

    public String toString(){
        return String.format("(%s, %s)", one, two);
    }

    public boolean equals(Object other){

        if(other == this){
            return true;
        }
        
        if( other instanceof Tuple ){
            Tuple t = (Tuple) other;
            return ( (one == null? t.one == null : one.equals( t.one ))
                  && (two == null? t.two == null : two.equals( t.two )) );
        }else{
            return false;
        }

    }

    public int hashCode(){
        return one.hashCode() + two.hashCode();
    }

}
